How to compile on Windows:
-------------------------
Windows mysql-5.0 package:
http://dev.mysql.com/downloads/mysql/5.0.html#win32
Linux mysql-5.0 package:
http://dev.mysql.com/downloads/mysql/5.0.html#linux-rhel5-x86-32bit-rpms

First timers:
1. Decompress the mysql-5.0.26.tar.gz file to "C:\mysql-5.0.26-win-src\mysql-5.0.26\include"

How to set up a UDF project:
Setting up a new UDF project involves 3 major steps (provided you have already installed the
mysql source): Creating the correct type of blank project, Setting up the project's skeleton
and configuring the Project appropriately.

Preliminary Steps:
1. If you haven't already, Decompress the mysql-5.0.26.tar.gz file to
   "C:\mysql-5.0.26-win-src\mysql-5.0.26\include"

Creating a blank project:
1. Right-Click on the solution and select "Add > New Project"
2. Expand "Visual C++ Projects " and Click on "Win32" then select "Win32 Project"
3. Give it a name beginning with "udf_" like "udf_my_function" and click OK
4. The dialog box "Win32 Application Wizard" will appear.
   On the left side are the menu items "Overview" and "Application Settings".
   Click on "Application Settings".
5. Select "DLL" as the "Application Type"
6. Select "Empty Project" under the "Additional Options"

Setting up the project's skeleton:
1. Add a ".cc" file in the "Source Files" folder.
2. Click on the file and look in the Properties pane (not the same as properties window).
3. Change "File Type" to "C/C++ Code"
4. Create a ".def" file. It doesn't need to be populated yet.

Configuring the Project
1. Right-Click on the project file and go to properties.
2. In the "C++" folder go to "General"
3. Add "C:\mysql-5.0.26-win-src\mysql-5.0.26\include" to the "Additional Include Directories"
4. In the "Linker" folder go to "Input"
5. Make sure the .def file is assigned and assign it if it isn't.




How to compile on Linux
-----------------------
Building the project on Linux is simpler because you don't have to deal with the
.NET project settings. However, it can also be problematic if you haven't already
gone through steps to compile MySQL before. As a result, we will continue with the
assumption that you have installed, configured, made and installed MySQL before.

If someone has already performed the preliminary steps you can go straight to the
compile steps. To verify whether or not the preliminary steps have been done
check for the existance of the /usr/local/mysql/include/mysql directory:
   $find /usr/local/mysql/include/mysql -type d \
    -exec echo "Preliminary step appears to have already been completed." \;

If you get a message "No such file or directory" then you need to perform the
preliminary steps.


Preliminary Steps:
1. Make sure you have the latest g++ library*:
   $yum install gcc-c++

2. If you haven't already, Decompress the mysql-5.0.26.tar.gz file and install it:
   $mkdir /mysql_5_0_26
   $mv mysql-5.0.26.tar.gz /mysql_5_0_26
   $gunzip mysql-5.0.26.tar.gz
   $tar -xf mysql-5.0.26.tar
   $mkdir /usr/local/mysql
   $cd mysql-5.0.26
   $./configure --prefix=/usr/local/mysql
   $make
   $make install

3. OPTIONAL: You may now remove your /mysql_5_0_26 directory if you wish.
   $cd /
   $rm -rf mysql_5_0_26

* For those who forgot to do step 1 in the preliminaries:

If you get the message "error trying to exec 'cc1plus'" you need to install
the C++ package then redo the commands starting at the "configure" command.

If you try to just rerun the "make" command instead of going back to the
"configure" command you will get another error: 
"redeclaration of C++ built-in type 'bool'"

Remember to repeat the steps starting from the "configure" command to get
through the compile.


Adding the udf source, compiling and installing it:
1. Go into the sql directory.
   $cd /usr/local/mysql
2. Add your .cc file here.
3. Compile the udf file - change "udf_my_function" below to reflect
   the correct UDF file name:
   $gcc -shared -lstdc++ \
    -I /usr/include \
    -I /usr/local/include \
    -I /usr/local/mysql/include \
    -I /usr/local/mysql/include/mysql \
    -o udf_my_function.so udf_my_function.cc
4. Copy the .so file to a place where mysql can use it:
   $cp udf_my_function.so /usr/lib
